package de.mhu.mandalaui.actions;

import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.List;

import de.mhu.mandalaui.Response;
import de.mhu.mandalaui.bind.Element;

public class SequenceAction extends Action {
	
	private LinkedList<Action> actions = new LinkedList<Action>();

	public SequenceAction() {
	}
	
	public SequenceAction(Action...actions) {
		for (Action a : actions)
			this.actions.add(a);
	}
	
	@Override
	public void renderFunctionImplementation(PrintWriter out) {
		out.println("function() {");
		for (Action a : actions) {
			if (a.getOwner() == null) a.setOwner(getOwner());
			a.renderFunctionCall(out);
		}
		out.println("}");
	}
	
	public List<Action> getActions() {
		return actions;
	}
	
	public void startRender(Response response) {
		super.startRender(response);
		for (Action a : actions) {
			response.registerAttribute(a);
			a.setOwner(getOwner());
			a.startRender(response);
		}
	}

	
	public void doRegister(Response response) {
		for (Action p : actions) {
			p.doRegister(response);
		}
	}


}
